package com.wky1.wang1.Controller;

import com.wky1.wang1.JwtUtils;
import com.wky1.wang1.Request;
import com.wky1.wang1.pojo.Denglu;
import com.wky1.wang1.service.DengluService;
import com.wky1.wang1.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/denglu")
@RestController
public class DengluController {
    @Autowired
   private DengluService dengluService;
    @PostMapping("/dl")
    public Request denglu(@RequestBody Denglu denglu){


          Denglu denglu1=dengluService.denglulist(denglu);
          //如果为空登录成功
          if(denglu1!=null){
              Map<String,Object> map=new HashMap<>();
              map.put("username",denglu1.getUsername());
              map.put("password",denglu1.getPassword());
             String jwt= JwtUtils.getJwt(map);
             return Request.success(jwt);
          }
          String msg="用户名或密码错误";
        return Request.error(msg);
    }
}
